App({
  onLaunch: function() {
    var that = this
    // wx.setStorageSync('userId', "123456789");
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
        that.globalData.code = res.code
      }
    })
  },

  getUserInfo: function() {
    var that = this
    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
        console.log(res)
        that.globalData.code = res.code
        var code = res.code
        wx.request({
          method: 'POST',
          url: 'https://www.zaishengwang.com/wx/toCheckUser.do',
          dataType: 'json',
          header: {
            'content-type': 'application/x-www-form-urlencoded;'
          },
          data: {
            code: code
          },
          success: function(res) {
            if (res.data.userVo == null) {
              that.globalData.openId = res.data.openId
              wx.reLaunch({
                url: '../registerOrLogin/register'
              })
            } else {
              that.globalData.userId = res.data.userVo.bId
              that.globalData.wxType = res.data.userVo.wxType
              wx.setStorageSync('userId', res.data.userVo.bId)
            }
          },
          fail: function(error) {}
        })
      }
    })
  },

  globalData: {
    userInfo: null,
    code: '',
    userId: '',
    // userId: '28540724601283557656642026587',
    openId: '',
    wxType: ''
  },

  preUrl: 'https://www.lvdaxia.com.cn/dabaozhan/wx_app/'
})
